-
Notifications
You must be signed in to change notification settings - Fork 259
chore: add properties to CNS logger calls #4059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
chore: add properties to CNS logger calls #4059
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a properties parameter to the CNS logger's Response function to enable logging additional context information, such as Network Container (NC) IDs, which helps with debugging and log filtering.
- Added
propertiesparameter to loggerResponsemethod signature across all implementations - Updated all existing
logger.Responsecalls to passnilfor the new properties parameter - Implemented properties logging in
publishNetworkContainermethod to include Network ID and NC ID
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| log/stdapi.go | Updated global Response function to pass nil for new properties parameter |
| log/logger.go | Added properties parameter to Logger.Response method and implemented property formatting |
| cns/restserver/util.go | Updated logger.Response calls to include nil properties parameter |
| cns/restserver/ipam.go | Updated logger.Response calls to include nil properties parameter |
| cns/restserver/api.go | Updated logger.Response calls and added properties map for publishNetworkContainer |
| cns/logger/v2/shim.go | Updated shim Response method to include properties parameter |
| cns/logger/log.go | Updated interface and global Response function signatures |
| cns/logger/cnslogger.go | Implemented properties formatting in CNS logger Response method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| func (logger *Logger) Response(tag string, response interface{}, returnCode int, returnStr string, properties any, err error) { | ||
| // Create a string for properties if they exist | ||
| props := "" | ||
| if properties != nil { | ||
| props = fmt.Sprintf(" Properties: %+v", properties) | ||
| } | ||
|
|
||
| if err == nil && returnCode == 0 { | ||
| logger.Printf("[%s] Sent %T %+v.", tag, response, response) | ||
| logger.Printf("[%s] Sent %T %+v.%s", tag, response, response, props) | ||
| } else if err != nil { | ||
| logger.Errorf("[%s] Code:%s, %+v %s.", tag, returnStr, response, err.Error()) | ||
| logger.Errorf("[%s] Code:%s, %+v %s.%s", tag, returnStr, response, err.Error(), props) | ||
| } else { | ||
| logger.Errorf("[%s] Code:%s, %+v.", tag, returnStr, response) | ||
| logger.Errorf("[%s] Code:%s, %+v.%s", tag, returnStr, response, props) | ||
| } | ||
| } |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The properties formatting logic is duplicated across multiple files (log/logger.go and cns/logger/cnslogger.go). Consider extracting this into a shared helper function to avoid code duplication.
| func (c *logger) Response(tag string, response any, returnCode types.ResponseCode, properties any, err error) { | ||
| c.logger.Response(tag, response, int(returnCode), returnCode.String(), properties, err) | ||
| if c.th == nil || c.disableTraceLogging { | ||
| return | ||
| } | ||
| var msg string | ||
| lvl := ai.InfoLevel | ||
|
|
||
| // Create a string for properties if they exist | ||
| props := "" | ||
| if properties != nil { | ||
| props = fmt.Sprintf(" Properties: %+v", properties) | ||
| } | ||
|
|
||
| switch { | ||
| case err == nil && returnCode == 0: | ||
| msg = fmt.Sprintf("[%s] Sent %T %+v.", tag, response, response) | ||
| msg = fmt.Sprintf("[%s] Sent %T %+v.%s", tag, response, response, props) | ||
| case err != nil: | ||
| msg = fmt.Sprintf("[%s] Code:%s, %+v %s.", tag, returnCode.String(), response, err.Error()) | ||
| msg = fmt.Sprintf("[%s] Code:%s, %+v %s.%s", tag, returnCode.String(), response, err.Error(), props) | ||
| lvl = ai.ErrorLevel | ||
| default: | ||
| msg = fmt.Sprintf("[%s] Code:%s, %+v.", tag, returnCode.String(), response) | ||
| msg = fmt.Sprintf("[%s] Code:%s, %+v.%s", tag, returnCode.String(), response, props) | ||
| } | ||
| c.sendTraceInternal(msg, lvl) | ||
| } |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The properties formatting logic is duplicated from log/logger.go. Consider extracting this into a shared helper function to avoid code duplication.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
This pull request is stale because it has been open for 2 weeks with no activity. Remove stale label or comment or this will be closed in 7 days |
Reason for Change:
I was recently debugging an NC-publication failure and noticed that when filtering CNS logs by NC ID, the CNS logs where CNS logs that its returning to the caller were filtered out. This was because these logs didn't include the NC ID.
I've added a
propertiesparameter to theResponsefunction on the CNS logger so that callers can log additional details, such as the NC ID.